<?php

App::uses('Controller', 'Controller');
App::uses('Security', 'Utility');

class AppController extends Controller {

    var $uses = array('Authpermission');

    function beforeFilter() {
        Security::setHash('md5');
        $action = $this->action;
        $controller = $this->name;
        $arr_allow = array('login', 'logout');
        if (!in_array($action, $arr_allow)) {
            if (!$this->Session->check('user.id')) {
                $this->redirect(array('controller' => 'authusers', 'action' => 'login'));
            } else {
                $resourcename = $controller . '/' . $action;
                $usergroupid = $this->Session->read('user.groupid');
                if ($this->Authpermission->checkresource($usergroupid, $resourcename) != 1) {
                    $this->Session->setFlash(__('Access deny for this resource.', true));
                    $this->redirect(array('controller' => 'authusers', 'action' => 'login'));
                }
            }
        }
    }
}